package com.vmove.childtrain.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.vmove.childtrain.R;
import com.vmove.childtrain.domain.TeamData;
import com.vmove.childtrain.utils.TimeUtils;

import java.text.DecimalFormat;

import androidx.annotation.Nullable;
import androidx.fragment.app.BaseDialogFragment;
import androidx.fragment.app.DialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 多组成绩显示框
 */
public class DegreeDialog_lesson3 extends BaseDialogFragment {


    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_close)
    ImageView ivClose;
    @BindView(R.id.tv_win)
    TextView tvWin;
    @BindView(R.id.tv_timeCostRed)
    TextView tvTimeCostRed;
    @BindView(R.id.tv_timeCostYellow)
    TextView tvTimeCostYellow;
    @BindView(R.id.tv_timeCostBlue)
    TextView tvTimeCostBlue;
    @BindView(R.id.tv_timeCostGreen)
    TextView tvTimeCostGreen;
    @BindView(R.id.tv_successRed)
    TextView tvSuccessRed;
    @BindView(R.id.tv_successYellow)
    TextView tvSuccessYellow;
    @BindView(R.id.tv_successBlue)
    TextView tvSuccessBlue;
    @BindView(R.id.tv_successGreen)
    TextView tvSuccessGreen;
    @BindView(R.id.tv_failedRed)
    TextView tvFailedRed;
    @BindView(R.id.tv_failedYellow)
    TextView tvFailedYellow;
    @BindView(R.id.tv_failedBlue)
    TextView tvFailedBlue;
    @BindView(R.id.tv_failedGreen)
    TextView tvFailedGreen;
    private View rootView;

    Unbinder unbinder;
    private int timeCost;
    private int success;
    private int faild;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.dialog_degree_lesson3, container, false);
        unbinder = ButterKnife.bind(this, rootView);
        initView(rootView);
        return rootView;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Material_Light_Dialog_NoActionBar_MinWidth);
        setCancelable(false);
        Bundle args = getArguments();
        timeCost = args.getInt("time", 0);
        success = args.getInt("success",0);
        faild = args.getInt("faild",0);
    }

    /**
     * 定义控件
     * @param rootView
     */
    private void initView(View rootView) {
//        tvTimeCostRed.setText(TimeUtils.convertToDifftime(TimeUtils.FORMAT_DAY_CN_3, timeCost));
//        tvTimeCostRed.setText(timeCost+"ms");
        float time = timeCost/1000f;
        DecimalFormat df = new DecimalFormat("0.00");
        String format = df.format(time);
        String[] split = format.split("\\.");
        tvTimeCostRed.setText(split[0]+"秒"+split[1]);
        tvFailedRed.setText(faild+"次");
        tvSuccessRed.setText(success+"分");
    }

    private int getMax(int redSuccess, int yellowSuccess, int blueSuccess, int greenSuccess) {
        int max=redSuccess;
        max = yellowSuccess>max?yellowSuccess:max;
        max = blueSuccess>max?blueSuccess:max;
        max = greenSuccess>max?greenSuccess:max;
        return max;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (null != unbinder) {
            unbinder.unbind();
        }
    }

    @OnClick(R.id.iv_close)
    public void onViewClicked() {
        this.dismiss();
    }
}
